package demo2;

//父类
class Animal{
    public String name;

    public Animal(String name) {
        this.name = name;
    }
}
//接口
interface IRunning{
     void run();
}
interface ISwimming{
     void swim();
}
interface IFly{
        void fly();
}


//先继承后接口
class Dog extends Animal implements IRunning{
//初始化类成员
    public Dog(String name) {
        super(name);
    }
    //重写接口的方法
    @Override
    public void run(){
        System.out.println(name+"正在用四条腿跑！");
    }
}

class Fish extends  Animal implements ISwimming{
    //初始化类成员
    public Fish(String name) {
        super(name);
    }
    //重写接口的方法
    @Override
    public void swim() {
        System.out.println(name+ "正在游泳！");
    }
}
class Bird extends Animal implements IFly{
    //初始化类成员
    public Bird(String name) {
        super(name);
    }
    //重写接口的方法
    @Override
    public void fly() {
        System.out.println(name+"正在飞");
    }
}
class Duck extends Animal implements IFly,IRunning,ISwimming{
    //初始化类成员
    public Duck(String name) {
        super(name);
    }
    //重写接口的方法
    @Override
    public void run() {
        System.out.println(name+"正在用两条腿跑！");
    }
    //重写接口的方法
    @Override
    public void swim() {
        System.out.println(name+ "正在游泳！");
    }
    //重写接口的方法
    @Override
    public void fly() {
        System.out.println(name+"正在飞");
    }
}

public class text {
    //只要实现了IRunning的接口的  都可以接收
    public static void walk(IRunning iRunning){
        iRunning.run();
        //可以理解为IRunning iRunning =  new Dog("旺财")
        //        iRunning.run();
    }
    public static void swim(ISwimming iSwimming){
        iSwimming.swim();
    }
    public static void main(String[] args) {

        walk(new Dog("旺财"));
        walk(new Duck("唐老鸭"));
        System.out.println("========================");
        swim(new Fish("鱼"));                                                  
        swim(new Duck("唐老鸭2号"));
    }
}
